/**
 * 
 */
package com.media.module.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * TODO DP
 * @author zhyc
 * 2016年7月14日下午12:57:27
 * DimenValues.java
 */
public class DimenValues {

	public final static int BASE_VALUE=60;
	private SharedPreferences mSharedPreferences;
	private final String SHARE_STROAGE = "share";
	private Context mContext;
	private static DimenValues mDimenValues;
	
	public static DimenValues getInstance(Context context) {
		if(mDimenValues==null)mDimenValues = new DimenValues(context);
		return mDimenValues;
	}
	
	public DimenValues (Context context){
		mContext = context;
	}
	
	public DimenValues (){
	}
	
	/**
	 * 将sp值转换为px值，保证文字大小不变
	 * 
	 * @param spValue
	 * @param context
	 *            （DisplayMetrics类中属性scaledDensity）
	 * @return
	 */
	public static int spToPx(Context context, float spValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (spValue * fontScale + 0.5f);
	}
	
	/**
	 * 
	 * dipToPx
	 * 
	 * @param context
	 * @param dipValue
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	public static int dipToPx(Context context, float dipValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}
	
	
	
	public SharedPreferences getSharedPreferences() {
		if (mSharedPreferences == null) {
			mSharedPreferences = mContext.getSharedPreferences(SHARE_STROAGE, 0);
		}
		return mSharedPreferences;
	}
	
	/**
	 * 修改Share值
	 * 
	 * @param params
	 *            key
	 * @param values
	 */
	public void setSharedPreferences(String params, String values) {
		Editor editor = getSharedPreferences().edit();
		editor.putString(params, values);
		editor.commit();
	}

	public void setSharedPreferences(String params, int values) {
		Editor editor = getSharedPreferences().edit();
		editor.putInt(params, values);
		editor.commit();
	}

	public int getSharePreferencesInteger(String parsms) {
		if (getSharedPreferences() == null)
			return 0;
		return mSharedPreferences.getInt(parsms, 0);
	}

	public String getSharePreferencesValue(String parsms) {
		if (getSharedPreferences() == null)
			return null;
		return mSharedPreferences.getString(parsms, "");
	}
}
